/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.alibaba.dubbo.admin.governance.service.impl;

import java.util.List;
import java.util.Map;

import com.alibaba.dubbo.admin.governance.service.UserService;
import com.alibaba.dubbo.admin.registry.common.domain.UserPO;
import com.alibaba.dubbo.admin.registry.common.util.Coder;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

/**
 * IBatisUserService
 *
 */
@Component
public class UserServiceImpl extends AbstractService implements UserService {

    @Value("${spring.root.password}")
    private String rootPassword;
    @Value("${spring.guest.password}")
    private String guestPassword;

    public void setRootPassword(String password) {
        this.rootPassword = (password == null ? "" : password);
    }

    public void setGuestPassword(String password) {
        this.guestPassword = (password == null ? "" : password);
    }

    @Override
    public UserPO findUser(String username) {
        if ("guest".equals(username)) {
            UserPO userPO = new UserPO();
            userPO.setUsername(username);
            userPO.setPassword(Coder.encodeMd5(username + ":" + UserPO.REALM + ":" + guestPassword));
            userPO.setName(username);
            userPO.setRole(UserPO.GUEST);
            userPO.setEnabled(true);
            userPO.setLocale("zh");
            userPO.setServicePrivilege("");
            return userPO;
        } else if ("root".equals(username)) {
            UserPO userPO = new UserPO();
            userPO.setUsername(username);
            userPO.setPassword(Coder.encodeMd5(username + ":" + UserPO.REALM + ":" + rootPassword));
            userPO.setName(username);
            userPO.setRole(UserPO.ROOT);
            userPO.setEnabled(true);
            userPO.setLocale("zh");
            userPO.setServicePrivilege("*");
            return userPO;
        }
        return null;
    }

    @Override
    public List<UserPO> findAllUsers() {
        // TODO Auto-generated method stub
        return null;
    }

    public Map<String, UserPO> findAllUsersMap() {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public UserPO findById(Long id) {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public void createUser(UserPO userPO) {
        // TODO Auto-generated method stub

    }

    @Override
    public void updateUser(UserPO userPO) {
        // TODO Auto-generated method stub

    }

    @Override
    public void modifyUser(UserPO userPO) {
        // TODO Auto-generated method stub

    }

    @Override
    public boolean updatePassword(UserPO userPO, String oldPassword) {
        // TODO Auto-generated method stub
        return false;
    }

    @Override
    public void resetPassword(UserPO userPO) {
        // TODO Auto-generated method stub

    }

    @Override
    public void enableUser(UserPO userPO) {
        // TODO Auto-generated method stub

    }

    @Override
    public void disableUser(UserPO userPO) {
        // TODO Auto-generated method stub

    }

    @Override
    public void deleteUser(UserPO userPO) {
        // TODO Auto-generated method stub

    }

    public List<UserPO> findUsersByServiceName(String serviceName) {
        // TODO Auto-generated method stub
        return null;
    }

}
